import {
	TAB_IMAGES,
	OPT_DELETE,
	OPT_CALL,
	TAB_DELIMAGES
} from './common.js'
// #ifdef APP-PLUS
import { DB } from "@/utils/offline/sqlite/dbinit.js";
// #endif
//巡检的所有接口
import * as XUNJIAN from '@/api/engineeringMaintenance/engineeringMaintenance.js'
import {deleteImg} from '@/api/doc.js' //获取图片

/** 离线缓存的选项数据对应的离线文件路径（或文件名） */
const _map = new Map();

//查询-获取图片信息
_map.set(deleteImg, {
	type: OPT_DELETE,
	beforeAction: {
		name: '删除图片',
		// 必要性 boolean, 为false时,该后置操作不会被执行
		required: param => true,
		type: OPT_CALL,
		method: async (param)=>{
			const result = await DB.select(`select 1 from images where id = ${param.id} and docInfoId > 0`)
			if(result.length > 0) {
				//删除的图片为离线前缓存的图片, 更新图片的删除状态为真
				//恢复网络后将这类图片的id同步到后端，进行实际意义上的删除
				await DB.execute(`insert into deletedImages values (${param.id})`)
			}
			return true
		}
	},
	where: param => `id=${param.id}`, 
	tableName: TAB_IMAGES,
})
export const apiDataMapping = _map;

